﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HotelManageSystem.Domain;
using HotelManageSystem.Domain.Infrastructure;
using HotelManageSystem.Models;
using Telerik.Web.Mvc;

namespace HotelManageSystem.Controllers
{
    public class HotelingHistoryController : Controller
    {
        //
        // GET: /HotelingHistory/
        private readonly IHotelingHistoryRepository _hotelingHistoryRepository;
        private readonly IClientRepository _clientRepository;
        private readonly IUnitOfWork _unitOfWork;
        public HotelingHistoryController(IHotelingHistoryRepository hotelingHistoryRepository,IClientRepository clientRepository, IUnitOfWork unitOfWork)
        {
            _hotelingHistoryRepository = hotelingHistoryRepository;
            _clientRepository = clientRepository;
            _unitOfWork = unitOfWork;
        }
        private IList<HotelingHistoryInfoModel> GetAllHotelingHistoryInfo()
        {
            var hotels = _hotelingHistoryRepository.GetAll().AsQueryable();
            var clients = _clientRepository.GetAll().AsQueryable();
            List<HotelingHistoryInfoModel> list = (from hotel in hotels
                                                   from client in clients
                                                   where hotel.ClientCollection.Contains(client)
                                                   select new HotelingHistoryInfoModel
                                                              {
                                                                  ID = hotel.ID,
                                                                  RoomID = hotel.Room.ID,
                                                                  ClientID = client.ID,
                                                                  Name = client.Name,
                                                                  CertID =client.CertID,
                                                                  PresonNum = hotel.PresonNum,
                                                                  EntetTime = hotel.EntetTime,
                                                                  OutTime = hotel.OutTime
                                                              }).ToList();

            return list;
        }


     
        

        public ActionResult ShowAllHotelingHistory()
        {
            
            return View(GetAllHotelingHistoryInfo());
        }
        [GridAction]
        public ActionResult TelerikAjax()
        {
            return View(new GridModel<HotelingHistoryInfoModel>(GetAllHotelingHistoryInfo()));
        }

      

    }
}
